﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Map_Editor.Effects;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System.Windows.Forms;

namespace Map_Editor
{
    public class Sidebar : DrawableGameComponent
    {
        SpriteBatch spritebatch;
        Rectangle rect;
        Texture2D bg;
        new Editor Game;
        LinkedList<Button> buttons;
        
        public Sidebar(Editor e) : base(e)
        {
            spritebatch = new SpriteBatch(e.GraphicsDevice);
            bg = e.Content.Load<Texture2D>("void");
            rect = new Rectangle(8 * Editor.WINDOW_WIDTH / 10, 0, 2 * Editor.WINDOW_WIDTH / 10, Editor.WINDOW_HEIGHT);
            buttons = new LinkedList<Button>();
            Game = e;
            Rectangle r = new Rectangle(0, 20, 1 * Editor.WINDOW_WIDTH / 10, 50);
            
            Button b = new Button(new PlateformEffect(), e.Content.Load<Texture2D>("Block"), r, this);
            buttons.AddLast(b);
            
            r.Y += 60;
            b = new Button(new SpawnEffect(), e.Content.Load<Texture2D>("KrisboolIdle"), r, this);
            buttons.AddLast(b);

            r.Y += 60;
            b = new Button(new EnnemySpawnEffect(), e.Content.Load<Texture2D>("Kris"), r, this); 
            buttons.AddLast(b);

            r.Y += 60;
            b = new Button(new EOLEffect(), e.Content.Load<Texture2D>("flecheD"), r, this);
            buttons.AddLast(b);
        }

        public override void Draw(GameTime gameTime)
        {
            Game.ViewportSidebar();
            
            spritebatch.Begin();
            spritebatch.Draw(bg, rect, Color.Gainsboro);
            Rectangle r = new Rectangle(0, 20, 140, 50);
            foreach (Button b in buttons)
            {
                b.Draw(spritebatch);
                r.Y += 40;
            }
            spritebatch.End();
            base.Draw(gameTime);
        }
        public override void Update(GameTime gameTime)
        {
            buttons.First.Value.sprite = Game.Map.Plateform;
            foreach (Button b in buttons)
            {
                b.Update(gameTime);
            }
            base.Update(gameTime);
        }
        public override void Initialize()
        {
            
            base.Initialize();
        }

        public void SetEffect(ClickEffect e)
        {
            Game.Effect = e;
        }
    }
}
